unit disrapor1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  wwdbedit, StdCtrls, Mask, Wwdotdot, Wwdbcomb, wwdblook, ppDB, ppDBPipe,
  ppModule, raCodMod, ppVar, ppBands, ppCtrls, ppStrtch, ppRegion,
  ppPrnabl, ppClass, ppCache, ppComm, ppRelatv, ppProd, ppReport,
  wwdbdatetimepicker, Db, ADODB, Grids, DBGrids, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGrid, ComCtrls,
  TXComp, TXRB, siComp;

type
  Tfdisrap1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Button1: TButton;
    GroupBox2: TGroupBox;
    Label12: TLabel;
    Label3: TLabel;
    Label13: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    carikodu: TwwDBEdit;
    wwDBComboBox2: TwwDBComboBox;
    FirmaAdi: TwwDBEdit;
    tipi: TwwDBLookupCombo;
    t1: TwwDBDateTimePicker;
    Button2: TButton;
    ppDBPipeline3: TppDBPipeline;
    ppReport1: TppReport;
    ppTitleBand1: TppTitleBand;
    ppLabel1: TppLabel;
    QRLabel9: TppLabel;
    ppHeaderBand1: TppHeaderBand;
    ppShape3: TppShape;
    ppLabel2: TppLabel;
    ppLabel3: TppLabel;
    ppLabel4: TppLabel;
    ppLabel5: TppLabel;
    ppLabel6: TppLabel;
    ppLabel7: TppLabel;
    ppLabel8: TppLabel;
    ppLabel9: TppLabel;
    ppLabel10: TppLabel;
    ppLabel12: TppLabel;
    ppDetailBand1: TppDetailBand;
    ppLine10: TppLine;
    ppLine3: TppLine;
    ppDBText1: TppDBText;
    ppDBText2: TppDBText;
    ppDBText3: TppDBText;
    ppDBText4: TppDBText;
    ppDBText5: TppDBText;
    ppDBText6: TppDBText;
    ppDBText7: TppDBText;
    ppDBCalc1: TppDBCalc;
    ppLine1: TppLine;
    ppLine4: TppLine;
    ppLine5: TppLine;
    ppLine6: TppLine;
    ppLine7: TppLine;
    ppLine8: TppLine;
    ppLine9: TppLine;
    ppLine11: TppLine;
    ppLine12: TppLine;
    ppLine14: TppLine;
    ppDBText9: TppDBText;
    ppFooterBand1: TppFooterBand;
    ppLine2: TppLine;
    ppSystemVariable1: TppSystemVariable;
    ppSystemVariable2: TppSystemVariable;
    rapor: TADOQuery;
    DataSource1: TDataSource;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1formno: TcxGridDBColumn;
    cxGrid1DBTableView1gittarih: TcxGridDBColumn;
    cxGrid1DBTableView1geltarih: TcxGridDBColumn;
    cxGrid1DBTableView1musteri: TcxGridDBColumn;
    cxGrid1DBTableView1serino: TcxGridDBColumn;
    cxGrid1DBTableView1oserino: TcxGridDBColumn;
    cxGrid1DBTableView1stokkodu: TcxGridDBColumn;
    cxGrid1DBTableView1cinsi: TcxGridDBColumn;
    cxGrid1DBTableView1dtfirma: TcxGridDBColumn;
    cxGrid1DBTableView1tekformno: TcxGridDBColumn;
    ExtraOptions1: TExtraOptions;
    procedure cariAra(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button2Click(Sender: TObject);
    procedure RadioButton4Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ppReport1PreviewFormClose(Sender: TObject);
    procedure ppDBCalc1GetText(Sender: TObject; var Text: string);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fdisrap1: Tfdisrap1;
  cariKod: integer;
implementation

uses data, distarap1, udmTeknik, cariaral, ucariara2, ana1;

{$R *.DFM}

procedure Tfdisrap1.cariAra(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  t: integer;
begin
  t := TwwDBEdit(sender).Tag;
  if (key = 13) then
  begin
    if ((sender as TwwDBEdit).text <> '') then
    begin
      dm.Cariara.Close;
      dm.Cariara.SQL.Clear;
      dm.Cariara.SQL.Add('select distinct carikod,KARGOKOD, carikodu, istihbarat,Tekyetkili, CTipi=(select adi from dbo.carituru where id=Tipi), FirmaAdi, Soyadi, ilce, Sehir,telefon3,KARGOADI=(select top 1 Ad from tbl_KargoTanim where ID=KARGOKOD) from Cari');

      dm.Cariara.SQL.Add('where (CariKod>0)');
      if t = 1 then
        dm.Cariara.SQL.Add('and (carikodu like ''' + TEdit(sender).text +
          '%'' )');
      if t = 2 then
        dm.Cariara.SQL.Add('and (FirmaAdi like ''' + TEdit(sender).text +
          '%'' )');
      dm.Cariara.Open;
      if (dm.CariAra.RecordCount = 1) then
      begin
        cariKod := dm.cariara.FieldByName('carikod').asInteger;
        carikodu.text := dm.cariara.FieldByName('CariKodu').asstring;
        FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
      end
      else
      begin
        if (dm.cariAra.RecordCount > 1) then
        begin
          if not assigned(fCariaraL) then
            fCariAraL := tfCariAral.create(self);
          if t = 1 then
          begin
            fCariAraL.siras := 'carikodu';
            fCariAraL.aranan := TEdit(sender).text;
          end;
          if t = 2 then
          begin
            fCariAraL.siras := 'FirmaAdi';
            fCariAraL.aranan := TEdit(sender).text;
          end;

          if fCariAraL.showmodal = mrOk then
          begin
            cariKod := dm.cariara.FieldByName('carikod').asInteger;
            carikodu.text := dm.cariara.FieldByName('CariKodu').asstring;
            FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
          end
          else
          begin
            fCariAra2 := tfCariAra2.create(self);
            if t = 1 then
              fCariAra2.edit3.Text := TEdit(sender).text;
            if t = 2 then
              fCariAra2.edit4.Text := TEdit(sender).text;
            if fCariAra2.showmodal = mrok then
            begin
              if dm.CariAra.Active = true then
              begin
                cariKod := dm.cariara.FieldByName('carikod').asInteger;
                carikodu.text := dm.cariara.FieldByName('CariKodu').asstring;
                FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
              end;
            end;
          end;
        end
        else
        begin
          fCariAra2 := tfCariAra2.create(self);
          if t = 1 then
            fCariAra2.edit3.Text := TEdit(sender).text;
          if t = 2 then
            fCariAra2.edit4.Text := TEdit(sender).text;
          fCariAra2.gelis := t;
          if fCariAra2.showmodal = mrok then
          begin
            if dm.CariAra.Active = true then
            begin
              cariKod := dm.cariara.FieldByName('carikod').asInteger;
              carikodu.text := dm.cariara.FieldByName('CariKodu').asstring;
              FirmaAdi.text := dm.cariara.FieldByName('firmaadi').asstring;
            end;
          end;
        end;
      end;
    end
    else
    begin
      carikod := 0;
      carikodu.text := '';
      Firmaadi.text := '';
    end;
  end;
end;

procedure Tfdisrap1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #27 then
    Close;

  if Key = #13 then
  begin
    Key := #0;
    Perform(CM_DialogKey, VK_TAB, 0);
  end;

end;

procedure Tfdisrap1.Button1Click(Sender: TObject);
begin
  dmTeknik.spdistakiprapor1.close;
  dmTeknik.spdistakiprapor1.Parameters.ParamByName('@carikod').value := carikod;
  if wwDBComboBox2.Text = '' then
    dmTeknik.spdistakiprapor1.Parameters.ParamByName('@durumu').value := ''
  else
    dmTeknik.spdistakiprapor1.Parameters.ParamByName('@durumu').value :=
      wwDBComboBox2.VALUE;

  if tipi.Text = '' then
    dmTeknik.spdistakiprapor1.Parameters.ParamByName('@Tipi').value := 0
  else
    dmTeknik.spdistakiprapor1.Parameters.ParamByName('@Tipi').value := Tipi.LookupValue;
  dmTeknik.spdistakiprapor1.open;

  QRLabel9.Caption := wwDBComboBox2.text;
  ppreport1.print;

  dmTeknik.spdistakiprapor1.DisableControls;
end;

procedure Tfdisrap1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  action := cafree;
  fdisrap1 := nil;
end;

procedure Tfdisrap1.Button2Click(Sender: TObject);
begin
  close;
end;

procedure Tfdisrap1.RadioButton4Click(Sender: TObject);
begin
  FirmaAdi.ReadOnly := false;
  carikodu.ReadOnly := false;
  FirmaAdi.color := clwhite;
  carikodu.color := clwhite;
end;

procedure Tfdisrap1.RadioButton3Click(Sender: TObject);
begin
  FirmaAdi.ReadOnly := true;
  carikodu.ReadOnly := true;
  FirmaAdi.color := $00E1FFFF;
  carikodu.color := $00E1FFFF;
end;

procedure Tfdisrap1.FormCreate(Sender: TObject);
begin
  cariKod := 0;
  if not dmTeknik.sptekniktipi.Active then
    dmTeknik.sptekniktipi.Open;
end;

procedure Tfdisrap1.ppReport1PreviewFormClose(Sender: TObject);
begin
  dmTeknik.spdistakiprapor1.enablecontrols;
end;

procedure Tfdisrap1.ppDBCalc1GetText(Sender: TObject; var Text: string);
begin
  if (not dmTeknik.spdistakiprapor1.FieldByName('gittarih').isnull) and
    (dmTeknik.spdistakiprapor1.FieldByName('gittarih').value < date - 3) and
    (dmTeknik.spdistakiprapor1.FieldByName('geltarih').isnull) then
  begin
    ppDBCalc1.font.Style := [fsbold];
    ppDBText1.font.Style := [fsbold];
    ppDBText2.font.Style := [fsbold];
    ppDBText3.font.Style := [fsbold];
    ppDBText4.font.Style := [fsbold];
    ppDBText5.font.Style := [fsbold];
    ppDBText6.font.Style := [fsbold];
    ppDBText7.font.Style := [fsbold];
  end
  else
  begin
    ppDBCalc1.font.Style := [];
    ppDBText1.font.style := [];
    ppDBText2.font.style := [];
    ppDBText3.font.style := [];
    ppDBText4.font.style := [];
    ppDBText5.font.style := [];
    ppDBText6.font.style := [];
    ppDBText7.font.style := [];
  end;

end;

procedure Tfdisrap1.FormShow(Sender: TObject);
begin
  anaform.CreateExport(Self);

  carikod := 5114;

  dm.spCari.Close;
  dm.spCari.Parameters.ParamByName('@carikod').value := carikod;
  dm.spCari.Open;

  carikodu.text := dm.spCari.FieldByName('carikodu').AsString;
  FirmaAdi.text := dm.spCari.FieldByName('FirmaAdi').AsString;
end;

end.
